package cn.gjxblog.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author gjx
 * @version v1.0
 * @Description 邮件服务
 * @date 2018/12/7 14:24
 */
@Service
public class MailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String sender;
    /**
     * 发送简单邮件
     * @param subject 主题
     * @param content  内容
     * @param toEmail 收件人
     */
    public void snedSimplMail(String subject,String content,String toEmail){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(sender);
        message.setTo(toEmail);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);
    }
}
